package com.hqyj.controller;



import com.hqyj.pojo.Role;
import com.hqyj.pojo.User;

import com.hqyj.pojo.UserRole;
import com.hqyj.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;

@Controller
@RequestMapping("user")
public class UserController {

    @Autowired
    UserService userService;

    //访问主页
    @RequestMapping("index")
    public String index() {
        return "index";
    }

    //访问登录页面
    @RequestMapping("loginPage")
    public String loginPage() {
        return "login";
    }

    //访问系统首页
    @RequestMapping("home")
    public String home() {
        return "home";
    }

    //访问无权限页面
    @RequestMapping("nopower")
    public String nopower() {
        return "nopower";
    }

    //登录提交
    @RequestMapping("loginForm")
    public String loginForm(User a, HashMap<String, Object> map) {
        return userService.login(a, map);
    }
    //新增
    @RequestMapping("add")
    @ResponseBody
    public HashMap<String,Object> add(User user){
        return userService.add(user);
    }
    //修改
    @RequestMapping("update")
    @ResponseBody
    public HashMap<String,Object> update(User user){
        return userService.update(user);
    }
    //删除
    @RequestMapping("del")
    @ResponseBody
    public HashMap<String,Object> del(Integer id){
        return userService.del(id);
    }
    //查询
    @RequestMapping("select")
    @ResponseBody
    public HashMap<String,Object> select(User user){
        return userService.select(user);
    }

    //分配
    @RequestMapping("fpRole")
    @ResponseBody
    public HashMap<String,Object> fpRole(UserRole userRole){
        return userService.fpRole(userRole);
    }

    //查询角色
    @RequestMapping("selectRole")
    @ResponseBody
    public HashMap<String,Object> selectRole(User user){
        return userService.selectRole(user);
    }

    //分配
    @RequestMapping("xgRole")
    @ResponseBody
    public HashMap<String,Object> xgRole(UserRole userRole){
        return userService.xgRole(userRole);
    }
}